/**
 *
 */
package com.angel.data.generator.result;

import java.util.ArrayList;
import java.util.List;

import com.angel.data.generator.interfaces.DataGenerator;

/**
 * @author William
 *
 */
public class DataGeneratorResult {

	private List<Class<? extends DataGenerator>> dataGenerators;
	
	public DataGeneratorResult(List<Class<? extends DataGenerator>> dataGenerators){
		super();
		this.dataGenerators = dataGenerators;
	}

	private <H extends DataGenerator> List<Class<? extends DataGenerator>> prepareBeforeDependenciesThat(Class<H> dependence) {
		int indexDependence = this.dataGenerators.indexOf(dependence);
		List<Class<? extends DataGenerator>> beforeDependencies = null;
		if(indexDependence >= 0){
			beforeDependencies = this.dataGenerators.subList(0, indexDependence);
		} else {
			beforeDependencies = new ArrayList<Class<? extends DataGenerator>>();
		}
		return beforeDependencies;
	}
	
	public <H extends DataGenerator> boolean areDependenciesBeforeThat(Class<H> dependence, Class<H>[] itsDependencies) {
		List<Class<? extends DataGenerator>> beforeDependece = this.prepareBeforeDependenciesThat(dependence); 
		boolean contains = true;
		if(itsDependencies != null && itsDependencies.length > 0){
			for(Class<H> a: itsDependencies){
				contains = beforeDependece.contains(a) && contains;
				if(!contains){
					break;
				}
			}
		}
		return contains;
	}
	
	public <T extends DataGenerator> List<Class<? extends DataGenerator>> dependenciesBeforeThat(Class<T> dependency) {
		return this.prepareBeforeDependenciesThat(dependency);
	}

	/**
	 * @return the dataGenerators
	 */
	public List<Class<? extends DataGenerator>> getDataGenerators() {
		return dataGenerators;
	}	
}
